package test02;

public class Cook extends Thread {


    @Override
    public void run() {
        while (true) {
            synchronized (Desk.lock) {
                //判断共享数据是否达到临界值,达到就结束线程
                if (Desk.count == 0) break;
                else {
                    //判断desk上是否还有饭,
                    if (Desk.foodflag == 1) {
                        //有就等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    } else {
                        //没有就做饭
                        Desk.foodflag = 1;
                        System.out.println(getName() + "已经做好饭");
                    }
                    //唤醒吃饭者进程
                    Desk.lock.notifyAll();
                }
            }
        }

    }


}
